package com.kmxd.ams.controller.jy;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kmxd.ams.client.jy.IAuthDatabaseSvc;
import com.kmxd.ams.client.jy.dto.AuthArchTypeDTO;
import com.kmxd.ams.client.jy.dto.AuthDatabaseAddDTO;
import com.kmxd.ams.client.jy.dto.AuthDatabaseEditDTO;
import com.kmxd.ams.client.jy.dto.AuthDatabaseQueryDTO;
import com.kmxd.ams.client.jy.vo.AuthDatabaseListVO;
import com.kmxd.ams.client.jy.vo.AuthDatabaseVO;
import com.kmxd.ams.client.jy.vo.AuthorizationUserVO;
import com.kmxd.ams.core.log.annotation.AutoLog;
import com.kmxd.ams.core.result.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 授权门类信息 前端控制器
 *
 * @author ZuoLG
 * @since 2023-11-30
 */
@RestController
@Tag(name = "授权门类信息")
@RequestMapping("/jy/authDatabase")
@AllArgsConstructor
public class AuthDatabaseCtl {

  private IAuthDatabaseSvc authDatabaseService;

  /** 分页查询 */
  @Operation(summary = "分页查询")
  @RequestMapping("/selectPage")
  @AutoLog(module = "授权门类信息", title = "分页查询")
  public R<Page<AuthDatabaseListVO>> selectPage(Page reqPage, AuthDatabaseQueryDTO req) {
    return R.success(authDatabaseService.selectPage(reqPage, req));
  }

  /** 列表查询 */
  @Operation(summary = "列表查询")
  @RequestMapping("/selectList")
  @AutoLog(module = "授权门类信息", title = "列表查询")
  public R<List<AuthDatabaseListVO>> selectList(AuthDatabaseQueryDTO req) {
    return R.success(authDatabaseService.selectList(req));
  }

  /** 新增 */
  @Operation(summary = "新增")
  @PostMapping("/add")
  @SaCheckPermission("jy:authDatabase:add")
  @AutoLog(module = "授权门类信息", title = "新增")
  public R<Void> add(@Validated @RequestBody AuthDatabaseAddDTO req) {
    authDatabaseService.add(req);
    return R.success();
  }

  /** 修改 */
  @Operation(summary = "修改")
  @PostMapping("/edit")
  @SaCheckPermission("jy:authDatabase:edit")
  @AutoLog(module = "授权门类信息", title = "修改")
  public R<Void> edit(@Validated @RequestBody AuthDatabaseEditDTO req) {
    authDatabaseService.edit(req);
    return R.success();
  }

  /** 删除 */
  @Operation(summary = "删除")
  @PostMapping("/remove")
  @SaCheckPermission("jy:authDatabase:remove")
  @AutoLog(module = "授权门类信息", title = "删除")
  public R<Void> remove(@RequestParam String ids) {
    authDatabaseService.remove(ids);
    return R.success();
  }

  /** 查看 */
  @Operation(summary = "查看")
  @GetMapping("/view")
  @AutoLog(module = "授权门类信息", title = "查看")
  public R<AuthDatabaseVO> view(@RequestParam Long id) {
    return R.success(authDatabaseService.view(id));
  }

  /** 给用户授权信息 */
  @Operation(summary = "给用户授权信息")
  @PostMapping("/setArchAuthByUserId")
  @AutoLog(module = "授权信息", title = "给用户授权信息")
  public R<Void> setArchAuthByUserId(@Validated @RequestBody AuthArchTypeDTO req) {
    authDatabaseService.setArchAuthByUserId(req);
    return R.success();
  }

  /** 根据用户ID获取相应授权信息 */
  @Operation(summary = "根据用户ID获取相应授权信息")
  @GetMapping("/getArchAuthByUserId")
  @AutoLog(module = "授权信息", title = "根据用户ID获取相应授权信息")
  public R<AuthorizationUserVO> getAuthByUserId(@RequestParam Long userId) {
    return R.success(authDatabaseService.getAuthByUserId(userId));
  }
}
